package com.javaee.xiangyang.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    AdminLoginInterceptor adminLoginInterceptor;

    @Resource
    UserLoginInterceptor userLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns("/**") 表示拦截所有的请求，
        // excludePathPatterns("/login", "/register") 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
        //拦截JAVAEE后台相关页面
        registry.addInterceptor(adminLoginInterceptor)
                .addPathPatterns(
                        "/Commodity/**",
                        "/Users/**",
                        "/Orders/**",
                        "/Admin/**"
                )
                .excludePathPatterns(
                        "/Admin/ToLogin",
                        "/Admin/Login"
                );

        //拦截JAVAEE前台相关页面
        registry.addInterceptor(userLoginInterceptor)
                .addPathPatterns(
                        "/MallCar/**",
                        "/MallGoods/**",
                        "/MallUser/**",
                        "/MallComment/**",
                        "/MallOrder/**"

                )
                .excludePathPatterns(
                        "/MallUser/UserRegister",
                        "/MallUser/UserLogin",
                        "/MallGoods/index"
                );

    }
}
